<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
          name="viewport">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>新建优惠券</title>
    <link rel="stylesheet" href="../css/base.css">
    <script src="../js/jquery-3.2.1.min.js"></script>
    <script src="../js/laydate/laydate.js"></script>
    <script src="../js/public.js"></script>
    <style>
        body{
            background: #fff;
        }
        .header{
            line-height:40px;
            background: #fff;
            color: #5f3104;
            text-align: right;
            padding-right: .2rem;
            box-sizing: border-box;
        }
        .flex{
            height: 40px;
            line-height: 40px;
            padding: 0 .2rem;
            box-sizing: border-box;
            position: relative;
        }
        input{
            border: none;
            float: right;
            text-align: right;
            margin: 10px 0;
            margin-right: .25rem;
        }
        .imgs{
            width: .18rem;
            position: absolute;
            right: .18rem;
            top: .18rem;
        }
    </style>
</head>

<body>
    <!--头部-->
    <div class="header" id="btn_post">
        完成
    </div>

    <!--正文-->
    <div class="New-coupons bc-gray">
        <form id="forms">

            <input type="hidden" name="storeid" id="storeid" value="">
        <ul>
            <li class="flex">
                <span>优惠券名称</span>
                <input type="text" placeholder="请填写优惠券名称" name="couponName" id="couponName">
                <img src="../img/下一步@2x.png" alt="" class="imgs">
            </li>
            <li class="flex">
                <span>优惠金额</span>
                <input type="tel" placeholder="请填写优惠金额" name="money" id="money">
                <img src="../img/下一步@2x.png" alt="" class="imgs">
            </li>
            <li class="flex">
                <span>优惠类型</span>
                <input type="text" placeholder="请填写优惠类型" name="condition" id="yhtype" onafterpaste="isNumber1(this)" onkeyup="isNumber1(this)">
                <img src="../img/下一步@2x.png" alt="" class="imgs">
            </li>
            <li class="flex">
                <span>发放数量</span>
                <input type="text" placeholder="请填写发放数量" name="num" id="ffnum">
                <img src="../img/下一步@2x.png" alt="" class="imgs">
            </li>
            <!--<li class="flex">-->
                <!--<span>备注</span>-->
                <!--<input type="text" placeholder="请填写备注" id="bz">-->
                <!--<img src="../img/下一步@2x.png" alt="" class="imgs">-->
            <!--</li>-->
     <!--       <li class="flex">
                <span>发放方式</span>
                <input type="text" placeholder="请填写发放方式" id="fftype">
                <img src="../img/下一步@2x.png" alt="" class="imgs">
            </li>-->
            <li class="flex">
                <span>开始时间</span>
                <input type="text" placeholder="请输入开始时间" name="startTime" id="starttime">
                <img src="../img/下一步@2x.png" alt="" class="imgs">

            </li>
            <li class="flex">
                <span>结束时间</span>
                <input type="text" placeholder="请输入结束时间"  name="endTime" id="endtime">
                <img src="../img/下一步@2x.png" alt="" class="imgs">

            </li>
        </ul>
        </form>
    </div>


    <script>

        function isNumber1(e){var t=$(e).val();t=1==t.length?t.replace(/[^0-9]/g,""):t.replace(/\D/g,""),$(e).val(t)}
        $(function () {
            $("#storeid").val(sessionStorage.getItem("s_id"));
            laydate.render({
                elem: '#starttime'
                ,type: 'datetime'
            });
            laydate.render({
                elem: '#endtime'
                ,type: 'datetime'
            });
            $("#btn_post").click(function (){
                if(isNull($("#couponName").val())){
                    alert("请填写优惠券名称");
                    return false;
                }
                if(isNull($("#money").val())){
                    alert("请填写金额");
                    return false;
                }
                if(isNull($("#yhtype").val())){
                    alert("请填写优惠方式");
                    return false;
                }
                if(isNull($("#ffnum").val())){
                    alert("请填写数量");
                    return false;
                }
           /*     if(isNull($("#bz").val())){
                    alert("请填写备注需求");
                    return false;
                }
                if(isNull($("#fftype").val())){
                    alert("请填写发放方式");
                    return false;
                }*/
                if(isNull($("#starttime").val())){
                    alert("请填写开始时间");
                    return false;
                }
                if(isNull($("#endtime").val())){
                    alert("请填写结束时间");
                    return false;
                }
//                console.log($("#forms").serialize());
                $.ajax({
                    url:base_url+"ZITAOHUI/coupon/add",
                    type:"post",
//                    data:{
//                        storeid:sessionStorage.getItem("s_id"),
//                        money:$("#money").val(),
//                        condition:$("#yhtype").val(),
//                        num:$("#ffnum").val(),
//                        startTime:$("#startTime").val(),
//                        endTime:$("#endTime").val()
//                    },
                    data:$("#forms").serialize(),
                    dataType:"json",
                    success:function (data){
                        console.log(data);
                        if(data.code == 1){
                            alert("添加成功");
                            window.location.href = 'Promotion-center.html';
                        }
                    },
                    error:function (error){
                        console.log(error);
                    }
                })
            });
        })
    </script>
</body>

</html>